import java.util.*;
public class NGuessNumber {
    public static List<Integer> generateAnswer() {
        ArrayList<Integer> list = new ArrayList<>();
        int a = 0;
        while (a < 4) {
            int b = 0;
            int daan = (int) (Math.random() * 10);
            for (int i = 0; i < list.size(); i++) {
                if (daan == list.get(i)) {
                    b = 1;
                    break;
                }
            }
            if (b == 0) {
                list.add(daan);
                a++;
            }
        }
        return list;
    }

    static List<Integer> getPlayerInput() {
        Scanner scanner = new Scanner(System.in);
        ArrayList<Integer> List1 = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            List1.add(scanner.nextInt());
        }
        return List1;
    }

    public static String compareGuessAnswer() {
        int a = 0, b = 0;
        List<Integer> daan = generateAnswer();
        List<Integer> sc = getPlayerInput();
            for (int i = 0; i < daan.size(); i++) {
                if (daan.get(i) == sc.get(i)) {
                    b++;
                }
                for (int j = 0; j < sc.size(); j++) {
                    if (daan.get(i) == sc.get(j)) {
                        a++;
                    }
                }
            }

        System.out.println("A表示存在且位置正确的数字个数，B表示存在且位置不正确的数字个数！");
        return a + "A" + b + "B";

    }
    public static boolean isWin(){
        boolean b = false;
        String s=compareGuessAnswer();
        int a=Integer.parseInt(s.substring(0,1));

        if(a==4){
            b=true;
        }else {
            b=false;
        }
        return b;

    }
    public static void main(String[] args) {
       while (true){
           int a = 0, b = 0;
           List<Integer> daan =generateAnswer();
           System.out.println("欢迎来到猜数字游戏:规则如下 输入4个0-9的整型数 输入完毕后会和电脑进行比较电脑会输出如 1A2B 即猜测的四个数字有3个是对的，有一个位置对，两个位置不对");
           System.out.println("请输入4个0-9的整型数");
           List<Integer> sc = getPlayerInput();
           for (int i = 0; i < daan.size(); i++) {
               if (daan.get(i) == sc.get(i)) {
                   b++;
               }
               for (int j = 0; j < sc.size(); j++) {
                   if (daan.get(i) == sc.get(j)) {
                       a++;
                   }
               }
           }
           if(a==4){
               System.out.println("你全对了恭喜");
               System.out.println(a+"A"+b+"B");
              break;
           } else{
               System.out.println(a+"A"+b+"B");
               System.out.println("可惜了只差一点点");
           }
           System.out.println("是否继续(y/n)(y为继续，n为结束)");
           Scanner scanner=new Scanner(System.in);
           String a1=scanner.next();
           if (a1.equals("n"))
               break;
       }
    }
}
